package com.myfojing.foshuoliaozhibingjing;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import androidx.core.app.NotificationCompat;

public class AlarmService extends IntentService {
    NotificationManager notificationManager;

    public AlarmService() {
        super("AlarmService");
    }

    @Override
    public void onHandleIntent(Intent intent) {
        sendNotification("做功课时间到。");
    }


    private void sendNotification(String msg) {

        notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);

        Notification notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("提醒")
                .setContentText("到了做功课的时间了。")
                .setWhen(System.currentTimeMillis())
                .setContentIntent(contentIntent)
                .build();

        notificationManager.notify(1, notification);

    }
}